package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: zhaoss
 * @Date: 2023/5/6 - 05 - 06 - 17:17
 * @Description: com.sky.controller.user
 * @version: 1.0
 */
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result pageOrders(OrdersPageQueryDTO dto){

        return ordersService.pageOrders(dto);
    }

    /**
     * 查询各个订单状态数量
     * @return
     */
    @GetMapping("/statistics")
    public Result getStatistics(){
        return ordersService.getStatistics();
    }

    /**
     * 订单详情
     * @return
     */
    @GetMapping("/details/{id}")
    public Result getDetails(@PathVariable Long id){
        return ordersService.getDetails(id);
    }

    /**
     *接单
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto) {
        return ordersService.confirm(dto);
    }

    /**
     *拒单
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        return ordersService.rejection(dto);
    }

    /**
     *取消定单
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        return ordersService.cancel(dto);
    }

    /**
     *派送定单
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        return ordersService.delivery(id);
    }
    /**
     *完成定单
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        return ordersService.complete(id);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
//        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
//        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
}
